/*
 * ComerciosAgregarFrame.java
 *
 * Created on 16 de abril de 2008, 12:06 PM
 */
package org.remolques.inscripcion;

import org.mybeans.Sesion;
import org.mybeans.ContribuyentesBeans;
import org.mybeans.ComerciosBeans;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;

/**
 *
 * @author  avbravo
 */
public class RemolquesInscripcionAgregarFrame extends javax.swing.JFrame {

    Sesion sesion;
    ContribuyentesBeans contribuyentesBeans;
    ComerciosBeans comerciosBeans;

    String idNew;
    String tipoIdNew;
    int IdRemolqueTipo;
    int IdRemolque;

    /** Creates new form ComerciosAgregarFrame */
    public RemolquesInscripcionAgregarFrame() {
        initComponents();
        sesion = new Sesion();
        comerciosBeans = new ComerciosBeans();
        contribuyentesBeans = new ContribuyentesBeans();

        /*
         * Fondo
         */

        
          
         

        jPanel3.setOpaque(false);
        setContentPane(jPanel3);

        /*
         * fin del fondo
         */

        java.util.Calendar ca = java.util.Calendar.getInstance();
        java.sql.Date mydate = new java.sql.Date(ca.getTimeInMillis());
        jFormattedTextFieldFechaInscripcion.setValue(mydate);
        jButtonCertificacion.setEnabled(false);

        AutoCompleteDecorator.decorate(this.jComboBoxMesPago);
        AutoCompleteDecorator.decorate(this.jComboBoxRemolqueTipo);
        AutoCompleteDecorator.decorate(this.jComboBoxUso);
        AutoCompleteDecorator.decorate(this.jComboBoxContribuyente);
        CargarComboContribuyentes();
        AutoCompleteDecorator.decorate(this.jComboBoxComercio);
        CargarComboComercios();
        AutoCompleteDecorator.decorate(this.jComboBoxRemolqueTipo);
        CargarComboRemolquesTipo();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldNumero = new javax.swing.JTextField();
        jButtonNuevo = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldMarca = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldModelo = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jTextFieldColor = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTextFieldCapacidad = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldChasis = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jLabel19 = new javax.swing.JLabel();
        jFormattedTextFieldFechaInscripcion = new javax.swing.JFormattedTextField();
        jLabel20 = new javax.swing.JLabel();
        jComboBoxMesPago = new javax.swing.JComboBox();
        jLabel15 = new javax.swing.JLabel();
        jComboBoxUso = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jTextFieldAnio = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jTextFieldValor = new javax.swing.JTextField();
        jButtonGuardar = new javax.swing.JButton();
        jButtonCertificacion = new javax.swing.JButton();
        jButtonLimpiar = new javax.swing.JButton();
        jButtonRegresar = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        jLabel22 = new javax.swing.JLabel();
        jFormattedTextFieldFechaLiquidacion = new javax.swing.JFormattedTextField();
        jButtonLiquidacionHoy = new javax.swing.JButton();
        jTextFieldLiquidacion = new javax.swing.JTextField();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextAreaDescripcion = new javax.swing.JTextArea();
        jLabel23 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jComboBoxContribuyente = new javax.swing.JComboBox();
        jLabel17 = new javax.swing.JLabel();
        jComboBoxComercio = new javax.swing.JComboBox();
        jComboBoxRemolqueTipo = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Inscripcion de Remolques");
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel3.setOpaque(false);

        jLabel1.setText("Numero");

        jTextFieldNumero.setColumns(35);
        jTextFieldNumero.setEditable(false);
        jTextFieldNumero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldNumeroActionPerformed(evt);
            }
        });

        jButtonNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/new.jpeg"))); // NOI18N
        jButtonNuevo.setToolTipText("Crear Nuevo");
        jButtonNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonNuevoActionPerformed(evt);
            }
        });

        jLabel2.setText("Marca");

        jLabel3.setText("Modelo");

        jLabel6.setText("Color");

        jLabel9.setText("Capacidad");

        jLabel13.setText("Tipo Remolque");

        jLabel4.setText("Chasis");

        jTextFieldChasis.setText("no tiene");

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Inscripcion"));
        jPanel4.setOpaque(false);

        jLabel19.setText("Fecha Inscripcion");

        jFormattedTextFieldFechaInscripcion.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));
        jFormattedTextFieldFechaInscripcion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jFormattedTextFieldFechaInscripcionActionPerformed(evt);
            }
        });

        jLabel20.setText("Mes Pago");

        jComboBoxMesPago.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }));

        jLabel15.setText("Uso");

        jComboBoxUso.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Comercial", "Particular", "Bicicleta", "Moto", "Remolque", "Taxi", "Volquete", "Tanque", "Sin Tipo" }));

        jLabel8.setText("Año");

        jLabel12.setText("Valor");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel15)
                    .addComponent(jLabel20)
                    .addComponent(jLabel19)
                    .addComponent(jLabel8)
                    .addComponent(jLabel12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldValor, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldAnio, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jComboBoxUso, 0, 151, Short.MAX_VALUE)
                        .addComponent(jComboBoxMesPago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jFormattedTextFieldFechaInscripcion)))
                .addContainerGap(42, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jFormattedTextFieldFechaInscripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxMesPago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel20))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxUso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jTextFieldAnio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(jTextFieldValor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButtonGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/save.png"))); // NOI18N
        jButtonGuardar.setToolTipText("Guardar");
        jButtonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarActionPerformed(evt);
            }
        });

        jButtonCertificacion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/certificacion.jpeg"))); // NOI18N
        jButtonCertificacion.setToolTipText("Certificacion");
        jButtonCertificacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCertificacionActionPerformed(evt);
            }
        });

        jButtonLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/escoba.png"))); // NOI18N
        jButtonLimpiar.setToolTipText("Limpiar");
        jButtonLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLimpiarActionPerformed(evt);
            }
        });

        jButtonRegresar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/regresar.jpeg"))); // NOI18N
        jButtonRegresar.setToolTipText("Regresar");
        jButtonRegresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRegresarActionPerformed(evt);
            }
        });

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Liquidacion"));
        jPanel6.setOpaque(false);

        jLabel22.setText("Fecha Liquidacion");

        jFormattedTextFieldFechaLiquidacion.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));
        jFormattedTextFieldFechaLiquidacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jFormattedTextFieldFechaLiquidacionActionPerformed(evt);
            }
        });

        jButtonLiquidacionHoy.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/hoy.png"))); // NOI18N
        jButtonLiquidacionHoy.setToolTipText("Hoy");
        jButtonLiquidacionHoy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLiquidacionHoyActionPerformed(evt);
            }
        });

        jTextAreaDescripcion.setColumns(20);
        jTextAreaDescripcion.setRows(5);
        jScrollPane3.setViewportView(jTextAreaDescripcion);

        jLabel23.setText("No. Liquidacion");

        jLabel7.setText("Descripcion");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7)
                .addGap(65, 65, 65)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(87, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel22)
                        .addGap(24, 24, 24))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel23)
                        .addGap(40, 40, 40)))
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jTextFieldLiquidacion, javax.swing.GroupLayout.PREFERRED_SIZE, 284, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                        .addComponent(jFormattedTextFieldFechaLiquidacion, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(22, 22, 22)
                        .addComponent(jButtonLiquidacionHoy, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(132, 132, 132))))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22)
                    .addComponent(jButtonLiquidacionHoy)
                    .addComponent(jFormattedTextFieldFechaLiquidacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel23)
                    .addComponent(jTextFieldLiquidacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)))
        );

        jLabel16.setFont(new java.awt.Font("DejaVu Sans", 1, 13)); // NOI18N
        jLabel16.setText("Dueño");

        jLabel11.setText("Contribuyente");

        jComboBoxContribuyente.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxContribuyenteItemStateChanged(evt);
            }
        });
        jComboBoxContribuyente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxContribuyenteActionPerformed(evt);
            }
        });

        jLabel17.setText("Comercio");

        jComboBoxComercio.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxComercioItemStateChanged(evt);
            }
        });
        jComboBoxComercio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxComercioActionPerformed(evt);
            }
        });

        jComboBoxRemolqueTipo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxRemolqueTipoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(33, 33, 33)
                        .addComponent(jTextFieldCapacidad, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel4)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel6))
                        .addGap(48, 48, 48)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldColor, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(jPanel3Layout.createSequentialGroup()
                                    .addComponent(jTextFieldNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(jButtonNuevo))
                                .addComponent(jTextFieldModelo)
                                .addComponent(jTextFieldMarca, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE))))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButtonGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonCertificacion, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(102, 102, 102)
                        .addComponent(jLabel16))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxContribuyente, javax.swing.GroupLayout.PREFERRED_SIZE, 383, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel17)
                        .addGap(41, 41, 41)
                        .addComponent(jComboBoxComercio, 0, 383, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel13)
                        .addGap(6, 6, 6)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jComboBoxRemolqueTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldChasis, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(33, 33, 33)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, 465, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(54, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jTextFieldNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonNuevo))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jTextFieldMarca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jTextFieldModelo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jTextFieldColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(jTextFieldCapacidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(jComboBoxRemolqueTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jTextFieldChasis, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel16)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jComboBoxContribuyente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel17)
                            .addComponent(jComboBoxComercio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButtonRegresar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonGuardar, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)
                            .addComponent(jButtonCertificacion, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)
                            .addComponent(jButtonLimpiar, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE))
                        .addGap(57, 57, 57))))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 442, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jTextFieldNumeroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldNumeroActionPerformed
}//GEN-LAST:event_jTextFieldNumeroActionPerformed

private void jButtonRegresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegresarActionPerformed

    dispose();
}//GEN-LAST:event_jButtonRegresarActionPerformed

private void jButtonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGuardarActionPerformed


    try {
        String SNumero = this.jTextFieldNumero.getText();

        if (SNumero == null || SNumero.equals("")) {
            JOptionPane.showMessageDialog(this, "Presione el boton Crear Nuevo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldNumero.requestFocus();
            return;
        }
        this.IdRemolque = Integer.parseInt(SNumero);
        if (IdRemolque <= 0) {
            JOptionPane.showMessageDialog(this, "Presione el boton Crear Nuevo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldNumero.requestFocus();
            return;
        }

        String Marca = this.jTextFieldMarca.getText();
        if (Marca == null || Marca.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese la marca", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldMarca.requestFocus();
            return;
        }
        String Modelo = this.jTextFieldModelo.getText();
        if (Modelo == null || Modelo.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el modelo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldModelo.requestFocus();
            return;
        }



        String color = this.jTextFieldColor.getText();
        if (color == null || color.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el color", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldColor.requestFocus();
            return;
        }
        String capacidad = this.jTextFieldCapacidad.getText();
        if (capacidad == null || capacidad.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese la capacidad", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldCapacidad.requestFocus();
            return;
        }
        String chasis = this.jTextFieldChasis.getText();
        if (chasis == null || chasis.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el numero de chasis", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldChasis.requestFocus();
            return;
        }

        String SAnio = jTextFieldAnio.getText();
        if (SAnio == null || SAnio.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el año", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldAnio.requestFocus();
            return;
        }
        int anio = Integer.parseInt(SAnio);
        if (anio <= 1900) {
            JOptionPane.showMessageDialog(this, "El año no es valido", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldAnio.requestFocus();
            return;
        }

        double valor;
        String SValor = jTextFieldValor.getText();
        if (SValor == null || SValor.equals("")) {
            // JOptionPane.showMessageDialog(this, "Ingrese el valor", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            // jTextFieldValor.requestFocus();
            // return;
            valor = 0;
        } else {
            valor = Double.parseDouble(SValor);
        }

        if (valor < 0) {
            JOptionPane.showMessageDialog(this, "Ingrese el valor", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldValor.requestFocus();
            return;
        }
        
        String Tipo = (String) this.jComboBoxRemolqueTipo.getSelectedItem();
        if (Tipo == null || Tipo.equals("")) {
            JOptionPane.showMessageDialog(this, "seleccione el tipo de remolque", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        String Uso = (String) this.jComboBoxUso.getSelectedItem();
        if (Uso == null || Uso.equals("")) {
            JOptionPane.showMessageDialog(this, "seleccione el uso", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        String MesPago = (String) this.jComboBoxMesPago.getSelectedItem();
        if (MesPago == null || MesPago.equals("")) {
            JOptionPane.showMessageDialog(this, "seleccione el mes de pago", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        String descripcion = this.jTextAreaDescripcion.getText();
        if (descripcion == null) {
            descripcion = "";
        }
        String sFecha = jFormattedTextFieldFechaInscripcion.getText();
        if (sFecha == null || sFecha.equals("")) {
            JOptionPane.showMessageDialog(this, "seleccione la fecha de inscripcion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jFormattedTextFieldFechaInscripcion.requestFocus();
        }

        String Liquidacion = this.jTextFieldLiquidacion.getText();
        if (Liquidacion == null) {
            Liquidacion = "";
        }

        if (sesion.Conectar() == false) {
            JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        String sqlquery = "select * from remolques where idmunicipio = ? and idremolque =?";
        PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
        psquery.setString(1, sesion.getIdmunicipio());
        psquery.setInt(2, this.IdRemolque);
        ResultSet rs = psquery.executeQuery();
        rs.next();
        int x = rs.getRow();

        if (x != 0) {
            JOptionPane.showMessageDialog(this, "Existe un remolque con ese codigo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            sesion.con.close();
            return;
        }

        String sql = "INSERT into remolques (idremolque, placa,marca,modelo, anio,chasis ," +
                "capacidad,valor,idremolquetipo,color, descripcion," +
                "uso, id, tipoid,hipotecado,secuestrado, " +
                "traspaso,activo,idmunicipio,pagoinscripcion,fechainscripcion," +
                "fecha,username,liquidacion,fechaliquidacion,mespago,fideicomiso) " +
                "values( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";


        PreparedStatement prest = sesion.con.prepareStatement(sql);

        prest.setInt(1, this.IdRemolque);
        prest.setString(2, ""); //placa

        prest.setString(3, Marca);
        prest.setString(4, Modelo);
        prest.setInt(5, anio);
        prest.setString(6, chasis);
        prest.setString(7, capacidad);
        prest.setDouble(8, valor);
        prest.setInt(9, this.IdRemolqueTipo);
        prest.setString(10, color);
        prest.setString(11, descripcion);
        prest.setString(12, Uso);
        prest.setString(13, this.idNew);
        prest.setString(14, this.tipoIdNew);
        prest.setString(15, "no");//hipotecado
        prest.setString(16, "no");//secuestrado
        prest.setString(17, "no"); //traspaso
        prest.setString(18, "si");//activo
        prest.setString(19, sesion.getIdmunicipio());
        prest.setString(20, "no");//pagoinscripcion

        java.util.Date myFecha = (java.util.Date) jFormattedTextFieldFechaInscripcion.getValue();
        java.sql.Date date = new java.sql.Date(myFecha.getTime());
        prest.setDate(21, date); //fecha inscripion

        java.util.Calendar ca = java.util.Calendar.getInstance();
        java.sql.Date mydate = new java.sql.Date(ca.getTimeInMillis());

        prest.setDate(22, mydate);
        prest.setString(23, sesion.getUsername());//hipotecado

        prest.setString(24, Liquidacion);//liquidacion


        String sFechaLiquidacion2 = jFormattedTextFieldFechaLiquidacion.getText();
        if (sFechaLiquidacion2 == null || sFechaLiquidacion2.equals("")) {
            prest.setDate(25, null);
        } else {
            java.util.Date myFechaLiquidacion = (java.util.Date) jFormattedTextFieldFechaLiquidacion.getValue();
            java.sql.Date dateLiquidacion = new java.sql.Date(myFechaLiquidacion.getTime());
            prest.setDate(25, dateLiquidacion); //fechaliquidacion

        }
        prest.setString(26, MesPago);
        prest.setString(27, "no"); //fideicomiso

        int count = prest.executeUpdate();
        sesion.con.close();
        sesion.setIdRemolque(this.IdRemolque);
        JOptionPane.showMessageDialog(this, "Inscripcion de Remolque Guardada exitosamente", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
        jButtonCertificacion.setEnabled(true);



    } catch (Exception ex) {
        System.out.println("Error" + ex);
        JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }

}//GEN-LAST:event_jButtonGuardarActionPerformed

private void jButtonLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLimpiarActionPerformed

    Limpiar();
}//GEN-LAST:event_jButtonLimpiarActionPerformed

private void jButtonNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNuevoActionPerformed

    try {
        Limpiar();


        if (sesion.Conectar() == false) {
            JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }

        String sqlquery = "select count(*) as total from remolques  where remolques.idmunicipio = ? ";
        PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
        psquery.setString(1, sesion.getIdmunicipio());

        ResultSet rs = psquery.executeQuery();
        rs.next();
        int total = 0;
        int x = rs.getRow();
        if (x == 0) {
            total = 0;
        } else {
            total = Integer.parseInt(rs.getString("total"));
        }

        total++;
        jTextFieldNumero.setText(String.valueOf(total));


        repaint();

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jButtonNuevoActionPerformed

private void jFormattedTextFieldFechaInscripcionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFormattedTextFieldFechaInscripcionActionPerformed
}//GEN-LAST:event_jFormattedTextFieldFechaInscripcionActionPerformed

private void jFormattedTextFieldFechaLiquidacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFormattedTextFieldFechaLiquidacionActionPerformed
}//GEN-LAST:event_jFormattedTextFieldFechaLiquidacionActionPerformed

private void jButtonCertificacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCertificacionActionPerformed

    try {
        String SNumero = this.jTextFieldNumero.getText();

        if (SNumero == null || SNumero.equals("")) {
            JOptionPane.showMessageDialog(this, "Presione el boton Crear Nuevo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldNumero.requestFocus();
            return;
        }
        this.IdRemolque = Integer.parseInt(SNumero);
        if (this.IdRemolque <= 0) {
            JOptionPane.showMessageDialog(this, "Presione el boton Crear Nuevo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldNumero.requestFocus();
            return;
        }

        String reportSource;
        String reportDest;

        this.tipoIdNew = this.tipoIdNew.trim();

        String sql;
        if (this.tipoIdNew.equals("contribuyentes")) {
            reportSource = sesion.getRutaReportes() + "RemolquesInscritosCertificacionContribuyentes.jrxml";

        } else {
            reportSource = sesion.getRutaReportes() + "RemolquesInscritosCertificacionComercios.jrxml";

        }
        Map<String, Object> params = new HashMap<String, Object>();


        if (sesion.Conectar() == false) {
            JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        JasperReport jasperReport =
                JasperCompileManager.compileReport(reportSource);
        params.put("P_IDREMOLQUE", this.IdRemolque);
        params.put("P_IDMUNICIPIO", sesion.getIdmunicipio());
        params.put("P_MUNICIPIO", sesion.getMunicipio());
        params.put("P_NOMBREUSUARIO", sesion.getUsuario());
        JasperPrint jasperPrint =
                JasperFillManager.fillReport(
                jasperReport, params, sesion.con);

        JasperViewer.viewReport(jasperPrint, false);

    } catch (JRException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(null, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jButtonCertificacionActionPerformed

private void jButtonLiquidacionHoyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLiquidacionHoyActionPerformed

    java.util.Calendar ca = java.util.Calendar.getInstance();
    java.sql.Date mydate = new java.sql.Date(ca.getTimeInMillis());

    jFormattedTextFieldFechaLiquidacion.setValue(mydate);
}//GEN-LAST:event_jButtonLiquidacionHoyActionPerformed

private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
    // TODO add your handling code here:
}//GEN-LAST:event_formWindowGainedFocus

private void jComboBoxContribuyenteItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxContribuyenteItemStateChanged
}//GEN-LAST:event_jComboBoxContribuyenteItemStateChanged

private void jComboBoxContribuyenteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxContribuyenteActionPerformed

    try {
        String temp = (String) jComboBoxContribuyente.getSelectedItem();
        if (temp == null || temp.equals("")) {
        } else {
            jComboBoxComercio.setSelectedIndex(0);
            int posicion = temp.indexOf("|");

            int posfinal = 0;
            if (posicion <= 0) {
                posfinal = 0;
            } else {
                posfinal = posicion - 1;
            }

            String contribuyente = temp.substring(0, posfinal);
            int tamano = temp.length();
            int nuevaposicion = posfinal + 2;
            String cedula = temp.substring(nuevaposicion, tamano);
cedula = cedula.trim();
            this.idNew = cedula;
            this.tipoIdNew = "contribuyentes";



        }
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(this, "Error  " + ex.getMessage(), "ComboBox  ActionPerformed", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jComboBoxContribuyenteActionPerformed

private void jComboBoxComercioItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxComercioItemStateChanged
    // TODO add your handling code here:
}//GEN-LAST:event_jComboBoxComercioItemStateChanged

private void jComboBoxComercioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxComercioActionPerformed
    // TODO add your handling code here:
    try {
        String temp = (String) jComboBoxComercio.getSelectedItem();
        if (temp == null || temp.equals("")) {
        } else {
            jComboBoxContribuyente.setSelectedIndex(0);
            int posicion = temp.indexOf("|");

            int posfinal = 0;
            if (posicion <= 0) {
                posfinal = 0;
            } else {
                posfinal = posicion - 1;
            }

            String comercio = temp.substring(0, posfinal);
            int posicionF = temp.lastIndexOf("|");

            int posfinalF = 0;
            if (posicionF <= 0) {
                posfinalF = 0;
            } else {
                posfinalF = posicionF - 1;
            }
            int tamano = temp.length();
            int nuevaposicion = posfinalF + 2;
            String codigo = temp.substring(nuevaposicion, tamano);
codigo = codigo.trim();
            this.idNew = codigo;
            this.tipoIdNew = "comercios";

        }
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(this, "Error  " + ex.getMessage(), "ComboBox  ActionPerformed", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jComboBoxComercioActionPerformed

private void jComboBoxRemolqueTipoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxRemolqueTipoActionPerformed
    // TODO add your handling code here:
    try {
        String temp = (String) jComboBoxRemolqueTipo.getSelectedItem();
        if (temp == null || temp.equals("")) {
            return;
        }
        temp = temp.trim();
        int posicion = temp.indexOf("|");

        int posfinal = 0;
        if (posicion <= 0) {
            posfinal = 0;
        } else {
            posfinal = posicion - 1;
        }

        String remolquetipo = temp.substring(0, posfinal);
        remolquetipo = remolquetipo.trim();

        int largo = temp.length();

        int inic = posfinal + 2;
        String sIdRemolqueTipo = temp.substring(inic, largo);
        sIdRemolqueTipo = sIdRemolqueTipo.trim();
        this.IdRemolqueTipo = Integer.parseInt(sIdRemolqueTipo);

        /*
         *
         */

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(this, "Error  " + ex.getMessage(), "ComboBox  ActionPerformed", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jComboBoxRemolqueTipoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new RemolquesInscripcionAgregarFrame().setVisible(true);
            }
        });
    }

    private void Limpiar() {
        this.jTextFieldNumero.setText("");
        this.jTextFieldMarca.setText("");
        this.jTextFieldModelo.setText("");

        this.jTextFieldColor.setText("");
        this.jTextAreaDescripcion.setText("");
        this.jTextFieldCapacidad.setText("");
        this.jTextFieldChasis.setText("");
        this.jTextFieldAnio.setText("");
        this.jTextFieldValor.setText("");

        jTextFieldLiquidacion.setText("");
        jFormattedTextFieldFechaLiquidacion.setText("");
        jButtonCertificacion.setEnabled(false);




    }

    private void CargarComboContribuyentes() {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String sqlquery = "select contribuyentes.cedula, contribuyentes.contribuyente from contribuyentes where idmunicipio='" + sesion.getIdmunicipio() + "' and activo='si' order by contribuyente";
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            ResultSet rs = psquery.executeQuery();
            jComboBoxContribuyente.removeAllItems();
            int count = 0;
            jComboBoxContribuyente.insertItemAt("", count);
            count = 1;
            while (rs.next()) {
                String contribuyente = rs.getString("contribuyente");
                contribuyente = contribuyente + " | " + rs.getString("cedula");
                jComboBoxContribuyente.insertItemAt(contribuyente, count);
                count++;
            }
            if (count != 0) {
                jComboBoxContribuyente.setSelectedIndex(0);
            }


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    private void CargarComboComercios() {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String sqlquery = "select comercios.comercio, comercios.ruc, comercios.idcomercio from comercios where idmunicipio='" + sesion.getIdmunicipio() + "' and activo='si' order by comercio";
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            ResultSet rs = psquery.executeQuery();
            jComboBoxComercio.removeAllItems();
            int count = 0;
            jComboBoxComercio.insertItemAt("", count);
            count = 1;
            while (rs.next()) {
                String comercio = rs.getString("comercio");
                String ruc = rs.getString("ruc");
                if (ruc == null || ruc.equals("")) {
                    ruc = "-";
                }
                comercio = comercio + " | " + ruc + " | " + rs.getString("idcomercio");
                jComboBoxComercio.insertItemAt(comercio, count);
                count++;
            }
            if (count != 0) {
                jComboBoxComercio.setSelectedIndex(0);
            }


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Metodo:CargarComboComercios()\nError " + ex.getMessage(), "Error.", JOptionPane.ERROR_MESSAGE);
        }
    }

    private void CargarComboRemolquesTipo() {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String sqlquery = "select idremolquetipo, remolquetipo from remolquestipo where idmunicipio='" + sesion.getIdmunicipio() + "' and activo='si' order by remolquetipo";
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            ResultSet rs = psquery.executeQuery();
            jComboBoxRemolqueTipo.removeAllItems();
            int count = 0;
            while (rs.next()) {
                String idremolque = rs.getString("remolquetipo");
                idremolque += " | " + rs.getString("idremolquetipo");


                jComboBoxRemolqueTipo.insertItemAt(idremolque, count);
                count++;
            }
            if (count != 0) {
                jComboBoxRemolqueTipo.setSelectedIndex(0);
            }


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error.", JOptionPane.ERROR_MESSAGE);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButtonCertificacion;
    private javax.swing.JButton jButtonGuardar;
    private javax.swing.JButton jButtonLimpiar;
    private javax.swing.JButton jButtonLiquidacionHoy;
    private javax.swing.JButton jButtonNuevo;
    private javax.swing.JButton jButtonRegresar;
    private javax.swing.JComboBox jComboBoxComercio;
    private javax.swing.JComboBox jComboBoxContribuyente;
    private javax.swing.JComboBox jComboBoxMesPago;
    private javax.swing.JComboBox jComboBoxRemolqueTipo;
    private javax.swing.JComboBox jComboBoxUso;
    private javax.swing.JFormattedTextField jFormattedTextFieldFechaInscripcion;
    private javax.swing.JFormattedTextField jFormattedTextFieldFechaLiquidacion;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTextArea jTextAreaDescripcion;
    private javax.swing.JTextField jTextFieldAnio;
    private javax.swing.JTextField jTextFieldCapacidad;
    private javax.swing.JTextField jTextFieldChasis;
    private javax.swing.JTextField jTextFieldColor;
    private javax.swing.JTextField jTextFieldLiquidacion;
    private javax.swing.JTextField jTextFieldMarca;
    private javax.swing.JTextField jTextFieldModelo;
    private javax.swing.JTextField jTextFieldNumero;
    private javax.swing.JTextField jTextFieldValor;
    // End of variables declaration//GEN-END:variables
}
